home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume3 / modgen < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  7.5 KB

  1. From: talcott!seismo!sun!calma!adams (Robert Adams)
  2. Subject: extract usenet moderator list from postings
  3. Reply-To: adams@calma.UUCP (Robert Adams)
  4. Newsgroups: mod.sources
  5. Approved: jpn@panda.UUCP
  6.  
  7. Mod.sources:  Volume 3, Issue 94
  8. Submitted by: seismo!sun!calma!adams (Robert Adams)
  9.  
  10.  
  11. The following is an awk script that builds the usenet moderators
  12. list for from the list of moderators posted to mod.newslists.
  13. I wish this operation was automatic (like checkgroups) but this
  14. makes maintaining it much easier.
  15.  
  16.     adams@calma.UUCP        -- Robert Adams
  17.     ...!{sun,ucbvax}!calma!adams
  18. ------------------ cut here ------------------
  19. #! /bin/sh
  20. # This is a shell archive, meaning:
  21. # 1. Remove everything above the #! /bin/sh line.
  22. # 2. Save the resulting text in a file.
  23. # 3. Execute the file with /bin/sh (not csh) to create the files:
  24. #    README
  25. #    modgen
  26. #    getpath
  27. # This archive created: Wed Jan 22 09:36:33 1986
  28. export PATH; PATH=/bin:$PATH
  29. echo shar: extracting "'README'" '(1308 characters)'
  30. if test -f 'README'
  31. then
  32.     echo shar: will not over-write existing file "'README'"
  33. else
  34. sed 's/^    X//' << \SHAR_EOF > 'README'
  35.     X*** Build moderators list from mod.newslists posting ***
  36.     X
  37.     X'modgen' is a script that attempts to build a moderators list
  38.     Xfor the usenet software from the list of moderators that is posted
  39.     Xto mod.newslists.  It attempts to find two portions of the
  40.     Xposted information: 1) a listing of other domain to uucp domain
  41.     Xmappings (lines with "==" in them), and 2) a listing of moderated
  42.     Xgroup to internet address mapping.  I then substitutes the uucp
  43.     Xaddress for the corresponding other domain address and outputs
  44.     Xthat list.
  45.     X
  46.     XThis list is then processed through a program called 'getpath'.
  47.     X'getpath' is a quick script that takes an internet formed address
  48.     Xand, using the pathalias generated file, creates a uucp path
  49.     Xaddress.  'getpath' does not know about other domains -- it is
  50.     Xonly good for uucp hosts so some use of 'grep' is made to
  51.     Xseperate address that are in the uucp domain from address in
  52.     Xother domains (at our site, we've modified sendmail.cf to fob
  53.     Xdomains off onto our smarter neighbors).
  54.     X
  55.     XThe output of 'modgen' is a correctly formatted moderators
  56.     Xlist all ready for placing into /usr/lib/news/moderators.  It
  57.     Xis always best, though, to check the file to just make sure.
  58.     X
  59.     XThis script worked on the posted moderators list for January 1986.
  60.     X
  61.     X    adams@calma.UUCP        -- Robert Adams
  62.     X    ...!{sun,ucbvax}!calma!adams
  63. SHAR_EOF
  64. if test 1308 -ne "`wc -c < 'README'`"
  65. then
  66.     echo shar: error transmitting "'README'" '(should have been 1308 characters)'
  67. fi
  68. fi # end of overwriting check
  69. echo shar: extracting "'modgen'" '(2524 characters)'
  70. if test -f 'modgen'
  71. then
  72.     echo shar: will not over-write existing file "'modgen'"
  73. else
  74. sed 's/^    X//' << \SHAR_EOF > 'modgen'
  75.     X#! /bin/sh
  76.     X#   6 Dec 85 Robert Adams: as released
  77.     X#  16 Dec 85 Robert Adams: check for uucpPath being null
  78.     X#
  79.     X#  This is a hack that reads the list of moderators the is
  80.     X#  posted to mod.newslists and attempts to build a
  81.     X#  /usr/lib/news/moderators file.  It depends greatly on the
  82.     X#  format of the information in the posting because the posting
  83.     X#  is in human readable form and is not easily parsed.
  84.     X#  There is one section that gives a internet to uucp address
  85.     X#  mapping (lines with double equals "==" in them) and another
  86.     X#  section that lists moderated groups and the internet
  87.     X#  address of the moderator.  This thing takes the first
  88.     X#  section and attempts to build the uucp "internet-like"
  89.     X#  addresses for the moderators.  It outputs this to a temp
  90.     X#  file and then invokes 'getpath' to change the uucp addresses
  91.     X#  into uucp paths.  The output is in the format of the moderators
  92.     X#  file.
  93.     X#  Invocation is:
  94.     X#     modgen < /usr/spool/news/mod/newslist/?? > /usr/lib/news/moderators
  95.     X#  but it usually best to look at the file and "clean it up".
  96.     X#
  97.     Xawk '
  98.     XBEGIN {
  99.     X    state = "begin";
  100.     X}
  101.     X#scan and fetch the internet to uucp mapping
  102.     X(state == "begin" || state == "uucpmapping") && /.*==.*/ {
  103.     X    uucpmap[$1] = $3;
  104.     X    state = "uucpmapping";
  105.     X}
  106.     X#scan upto the final table
  107.     Xstate == "uucpmapping" && /^Group[    ]*Submissions$/ {
  108.     X    state = "modmapping";
  109.     X}
  110.     X#suck up the group to internet address mapping
  111.     Xstate == "modmapping" && /.*@.*/ {
  112.     X    modgroup[$1] = $1;
  113.     X    modmap[$1] = $2;
  114.     X    # (some entries have two addresses seperated by comma. Remove second one)
  115.     X    if (index(modmap[$1], ",")) {
  116.     X        modmap[$1] = substr(modmap[$1], 1, index(modmap[$1], ",")-1 );
  117.     X    }
  118.     X}
  119.     XEND {
  120.     X    if (state == "modmapping") {
  121.     X        # for each internet addr, replace internet host with uucp host
  122.     X        for (mod in modgroup) {
  123.     X            host = substr(modmap[mod], index(modmap[mod], "@")+1);
  124.     X            if (length(uucpmap[host])) {
  125.     X                modmap[mod] = substr(modmap[mod], 0, index(modmap[mod], "@"));
  126.     X                modmap[mod] = modmap[mod] uucpmap[host];
  127.     X            }
  128.     X        }
  129.     X        # output all of the addresses
  130.     X        for (mod in modgroup)
  131.     X            print modgroup[mod] "        " modmap[mod];
  132.     X    }
  133.     X    else {
  134.     X        print "invalid input file format";
  135.     X    }
  136.     X}
  137.     X' > /tmp/modgenA$$
  138.     Xset - `grep ".uucp$" /tmp/modgenA$$`
  139.     X# for each uucp domain addr, map internet addr to uupc path
  140.     Xwhile [ "X$1" != "X" ] ; do
  141.     X    uucpPath=`getpath $2`
  142.     X    if [ "$uucpPath" = "" ] ; then
  143.     X        uucpPath=$2
  144.     X    fi
  145.     X    echo $1 "        " $uucpPath >> /tmp/modgenB$$
  146.     X    shift; shift
  147.     Xdone
  148.     X# combine uucp and other domain address lines
  149.     Xgrep -v ".uucp$" /tmp/modgenA$$ | cat - /tmp/modgenB$$
  150.     Xrm /tmp/modgen[A-Z]$$
  151. SHAR_EOF
  152. if test 2524 -ne "`wc -c < 'modgen'`"
  153. then
  154.     echo shar: error transmitting "'modgen'" '(should have been 2524 characters)'
  155. fi
  156. chmod +x 'modgen'
  157. fi # end of overwriting check
  158. echo shar: extracting "'getpath'" '(1554 characters)'
  159. if test -f 'getpath'
  160. then
  161.     echo shar: will not over-write existing file "'getpath'"
  162. else
  163. sed 's/^    X//' << \SHAR_EOF > 'getpath'
  164.     X#!/bin/csh -f
  165.     X#   1 Dec 85 Tim Radzykewycz: as released
  166.     X#   2 Jan 86 Robert Adams: removed debugging, parameterized things, commented
  167.     X#
  168.     Xset BANG = '\!'
  169.     Xset PathFile = "/usr/spool/uumap/paths"
  170.     X#
  171.     X#  Find host name and user name.  This should be able to parse
  172.     X#  addresses of the form uname@host and host!uname, and the
  173.     X#  first form should have priority, so that the combined
  174.     X#  form 'host1!uname@host0' can be used.
  175.     X#  Notice that this doesn't know about domaining!  In fact, it
  176.     X#  strips any internet type domaining out before doing the host
  177.     X#  search in the PathFile.
  178.     X#
  179.     X#  Invocation is:  getpath address
  180.     X#  where getpath will output to standard out the path to the
  181.     X#  user found in the PathFile.  If no path is found, the
  182.     X#  unmodified path is output.  If no "address" is given, getpath
  183.     X#  reads it from standard input.
  184.     X#
  185.     Xecho $1 | sed 's/\..*//' > /tmp/$$
  186.     Xif ("$1" == "") then
  187.     X    echo $< | sed 's/\..*//' > /tmp/$$
  188.     Xendif
  189.     Xgrep -s '@' /tmp/$$
  190.     X# if there were matches, use form 'uname@host'
  191.     Xif ($status == 0) then
  192.     X    set host = `sed -e "s/.*@//" /tmp/$$`
  193.     X    set uname = `sed -e "s/${host}//" -e "s/@//" /tmp/$$`
  194.     Xelse
  195.     X    set host = `sed -e "s/${BANG}.*//" /tmp/$$`
  196.     X    set uname = `sed -e "s/${host}//" -e "s/${BANG}//" /tmp/$$`
  197.     Xendif
  198.     X#
  199.     X#  Now, find the path to that host, and tack on the uname
  200.     X#  to the end of it.
  201.     Xset e_path = `grep "^${host}    " $PathFile`
  202.     Xset uupath=`echo ${e_path} | sed -e 's/.*[     ]//' -e "s/%s/${uname}/" | sed -e "s/${BANG}${BANG}/${BANG}/g"`
  203.     Xif ("$uupath" == "") then
  204.     X    set uupath=`cat /tmp/$$`
  205.     Xendif
  206.     Xecho $uupath
  207.     Xrm -f /tmp/$$
  208. SHAR_EOF
  209. if test 1554 -ne "`wc -c < 'getpath'`"
  210. then
  211.     echo shar: error transmitting "'getpath'" '(should have been 1554 characters)'
  212. fi
  213. chmod +x 'getpath'
  214. fi # end of overwriting check
  215. #    End of shell archive
  216. exit 0
  217.  
  218.